home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / envoy / netprobe_4_24.lha / NetProbe / src / Timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-11  |  2.0 KB  |  93 lines

  1. //
  2. //  $Log: Timer.c,v $
  3. //  Revision 1.4  1994/07/11  21:54:10  hakan
  4. //  Mainly cosmetic changes
  5. //
  6. //  Revision 1.3  1994/06/20  00:07:14  hakan
  7. //  Returnes TimeRequests are primed with 0.2 seconds
  8. //
  9. //  Revision 1.2  1994/06/19  15:22:34  hakan
  10. //  Fini,  for starters
  11. //
  12. //  Revision 1.1  1994/06/19  15:00:12  hakan
  13. //  Initial revision
  14. //
  15. //
  16.  
  17. static char* RCSId = "$Id: Timer.c,v 1.4 1994/07/11 21:54:10 hakan Exp $";
  18.  
  19.  
  20.  
  21. static short                TimerDevFlag = 0;
  22. static struct timerequest*  TimerReq     = NULL;
  23. static struct MsgPort*      TimerPort    = NULL;
  24. static struct Library*      TimerBase    = NULL;
  25.  
  26.  
  27.  
  28. BOOL CreateTimer (void)
  29. {
  30.     if  (TimerPort = (struct MsgPort *) CreateMsgPort ())
  31.     {
  32.         if  (TimerReq = (struct timerequest *) CreateIORequest (TimerPort, sizeof (struct timerequest)))
  33.         {
  34.             if  (TimerDevFlag = !OpenDevice (TIMERNAME, UNIT_MICROHZ, (struct IORequest *) TimerReq, 0L))
  35.             {
  36.                 TimerBase = (struct Library *) TimerReq->tr_node.io_Device;
  37.  
  38.                 TimerReq->tr_node.io_Message.mn_ReplyPort   = TimerPort;
  39.                 TimerReq->tr_node.io_Command                = TR_ADDREQUEST;
  40.                 TimerReq->tr_node.io_Flags                  = 0L;
  41.                 TimerReq->tr_node.io_Error                  = 0L;
  42.  
  43.                 return (TRUE);
  44.             }
  45.         }
  46.     }
  47.  
  48.     return (FALSE);
  49. }
  50.  
  51.  
  52.  
  53. void DestroyTimer (void)
  54. {
  55.     if (TimerReq)
  56.     {
  57.         AbortIO ((struct IORequest*) TimerReq);
  58.         //  WaitIO ((struct IORequest*)  TimerReq);
  59.     }
  60.  
  61.     if (TimerDevFlag)
  62.     {
  63.         CloseDevice ((struct IORequest *) TimerReq);
  64.     }
  65.  
  66.     if (TimerReq)
  67.     {
  68.         DeleteIORequest (TimerReq);
  69.     }
  70.  
  71.     if (TimerPort)
  72.     {
  73.         DeleteMsgPort (TimerPort);
  74.     }
  75. }
  76.  
  77.  
  78.  
  79. struct IORequest* TimeRequest (void)
  80. {
  81.     TimerReq->tr_time.tv_secs   = 0;
  82.     TimerReq->tr_time.tv_micro  = 200000;   //  1E6 / 5
  83.  
  84.     return (TimerReq);
  85. }
  86.  
  87.  
  88.  
  89. struct MsgPort* TimePort (void)
  90. {
  91.     return (TimerPort);
  92. }
  93.